import vscode from 'vscode';
export function setEditorDecoration(context: { subscriptions: vscode.Disposable[]; }) {
  const editor = vscode.window.activeTextEditor;
  if (editor) {
    const position = editor.selection.active;
    const decorationType = vscode.window.createTextEditorDecorationType({
      color: '',
    });

    editor
      .edit((editBuilder) => {
        editBuilder.insert(position, '这是添加的文本');
      })
      .then(() => {
        const endPosition = position.translate(0, '这是添加的文本'.length);
        const range = new vscode.Range(position, endPosition);
        editor.setDecorations(decorationType, [range]);

        // 监听按键事件
        const disposable = vscode.workspace.onDidChangeTextDocument((event) => {
          if (
            event.contentChanges.length > 0 &&
            event.contentChanges[0].text === '\t'
          ) {
            decorationType.dispose();
            disposable.dispose();
          }
        });

        context.subscriptions.push(disposable);
      });
  }
}
